<style lang="less">
    @import "../../../../basic/pages/image/upload-file/filePreview.less";
    .title-text span {
        display: block;
        position: relative;
        color: black;
        font-weight: bold;
        text-align: center;
    }

    .title-text span:before, .title-text span:after {
        content: '';
        position: absolute;
        top: 50%;
        background: #dfdfdf;
        width: 44%;
        height: 1px;
    }

    .title-text span:before {
        left: 0;
    }

    .title-text span:after {
        right: 0;
    }

    .leaveComments {
        position: fixed;
        top: 50%;
        right: 10%;
        transform: translateY(-50%);
        margin-top: 40px;
        z-index: 99;
    }

    .leaveComments .detail_comment {
        position: absolute;
        background-color: white;
        width: 234px;
        height: 264px;
        box-shadow: 0px 0px 18px #ccc;
        top: -220px;
        right: 0px;
        transition: left 2s;
    }

    .leaveComments .detail_comment > h2 {
        background-color: #0D8EF5;
        font-weight: normal;
        font-size: 16px;
        color: white;
        padding: 5px 0px 5px 10px;
        line-height: 20px;
    }

    .leaveComments .detail_comment p {
        margin: 10px;
    }

    .leaveComments .detail_comment textarea {
        outline: none;
        resize: none;
        width: 100%;
        border-color: #ccc;
    }

    .selectOption .ivu-select-dropdown-list {
        max-height: 200px;
        overflow: auto;
    }
</style>
<template>
    <card>
    <div style="background-color: rgb(255,255,255)">
        <Row style="">
            <Form inline :label-width="120">
                <Form-item style="float: right;">
                    <Button id="saveButton" v-if="this.modelType != 2 && this.saveType==4" v-bind:disabled="is.disabled"
                            @click="Save('companyForm')" type="primary" size="large"
                            style="margin-right:24px;border: none;">暂存
                    </Button>
                    <Button id="commitButton" v-if="this.modelType != 2" @click="Commit('companyForm')" type="primary"
                            size="large" style=" margin-right:24px;color:white;">提交
                    </Button>
                    <!-- <Button id="applyButton" v-if="this.modelType == 2 && this.showType == 1"
                            @click="blacklist('companyForm')" type="primary" size="large"
                            style=" margin-right:24px;color:white;display: none">黑名单申请
                    </Button> -->
                    <Button @click="closeThisTag"  type="primary" size="large"
                            style="color:white;">返回
                    </Button>
                    <Spin size="large" fix v-if="spinShow"></Spin>
                </Form-item>
            </Form>
        </Row>
        <div>
            <h2 class="title-text"><span id="companyType">第三方挂靠公司信息</span></h2>
            <Form ref="companyForm" :model="companyForm" :rules="companyFormValidate" :label-width="160"
                  style="margin-top: 5px">
                <Row>
                    <i-col span="8">
                        <Form-item label="合作商名称" prop="channelId" v-if="this.modelType == 0">
                            <Select class="selectOption" v-model="companyForm.channelId" filterable clearable
                                    style="width: 200px;" size="default"
                                    @on-change="selectChannel(companyForm.channelId)">
                                <Option v-for="item in channelList" :value='item.id' :key="item.id">{{item.channelFullName}}</Option>
                            </Select>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="挂靠公司名称" prop="affiliatedName">
                            <Input type="text" size="default" v-bind:disabled="disabled"
                                   v-model="companyForm.affiliatedName" clearable placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="统一社会信用代码" prop="socUniCrtCode">
                            <Input type="text" size="default" v-bind:disabled="is.disabled"
                                   v-model="companyForm.socUniCrtCode" clearable placeholder="请输入"
                                   style="width: 200px" maxlength="18" @keyup.native="socValite"/>
                        </Form-item>
                    </i-col>
                </Row>
                <Row>
                    <i-col span="8">
                        <Form-item label="是否有道路运输许可证" :label-width="200" prop="whetherLicence">
                            <RadioGroup v-model="companyForm.whetherLicence" v-bind:disabled="disabled" size="default"
                                        @on-change="selectRadio">
                                <Radio v-bind:disabled="disabled" label="1">是</Radio>
                                <Radio v-bind:disabled="disabled" label="0">否</Radio>
                            </RadioGroup>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="道路运输许可证有效期至" prop="transPermitValidity">
                            <i-col span="8">
                                <Date-picker type="date" v-bind:disabled="disabledTime" size="default"
                                             v-model="companyForm.transPermitValidity" placeholder="选择日期"
                                             style="width: 200px"></Date-picker>
                            </i-col>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item
                            label="营业期限至"
                            :rules="companyForm.longTermOrNot?null:requeirOprTermValidity"
                            prop="oprTermValidity"
                        >
                            <Date-picker

                                v-bind:disabled="companyForm.disabled"
                                type="date"
                                size="default"
                                v-model="companyForm.oprTermValidity"
                                placeholder="选择日期"
                                style="width: 200px"></Date-picker>
                            <Checkbox v-bind:disabled="disabled" v-model="companyForm.longTermOrNot"
                                      @on-change="selectCheck">长期
                            </Checkbox>
                        </Form-item>
                    </i-col>
                </Row>
                <Row>
                    <i-col span="8">
                        <Form-item label="法定代表人姓名" prop="legalPersonName">
                            <Input type="text" v-bind:disabled="disabled" size="default"
                                   v-model="companyForm.legalPersonName" clearable placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="法人联系方式" prop="legalPersonTel">
                            <Input type="text" v-bind:disabled="disabled" size="default"
                                   v-model="companyForm.legalPersonTel" clearable placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="法人身份证号码" prop="legalPersonIdcard">
                            <Input type="text" v-bind:disabled="disabled" size="default"
                                   v-model="companyForm.legalPersonIdcard" clearable placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                </Row>
                <Row>
                    <i-col span="8">
                        <Form-item label="成立时间" prop="foundedTime">
                            <Date-picker :options="options" @on-change="changeOperationYears" type="date"
                                         v-bind:disabled="disabled" size="default" v-model="companyForm.foundedTime"
                                         placeholder="选择日期" style="width: 200px"></Date-picker>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="已运营年限" prop="operationYears">
                            <Input type="text" id="operation_year" disabled="disabled" size="default"
                                   v-model="companyForm.operationYears" clearable placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="注册资本" prop="registeredCapital">
                            <Input type="text" maxlength="14" size="default" v-bind:disabled="disabled"
                                   v-model="companyForm.registeredCapital" clearable placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                </Row>
                <Row>
                    <i-col span="8">
                        <FormItem label="注册省市" prop="domicLocation">
                            <Cascader :data="location" v-model="companyForm.domicLocation" style="width:200px;"
                                      size="default" v-bind:disabled="disabled" :clearable=false
                                      :load-data="loadData"></Cascader>
                        </FormItem>
                    </i-col>
                    <i-col span="8">
                        <form-item label="详细地址" prop="registeredAddress">
                            <Input v-bind:disabled="disabled" v-model="companyForm.registeredAddress" size="default"
                                   style="width: 200px" placeholder="请输入"/>
                        </form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="备案有效期至" prop="validityTime">
                            <i-col span="8">
                                <Date-picker v-bind:disabled="disabled" type="date" size="default"
                                             v-model="companyForm.termValidity" placeholder="选择日期"
                                             style="width: 200px"></Date-picker>
                            </i-col>
                        </Form-item>
                    </i-col>
                </Row>
                <Row>
                    <i-col span="8">
                        <Form-item label="自有运营车辆数" prop="operateVehicles">
                            <Input type="text" v-bind:disabled="disabled" size="default"
                                   v-model="companyForm.operateVehicles" clearable placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="经营状态" prop="operateStatus">
                            <Select v-model="companyForm.operateStatus" v-bind:disabled="disabled" placeholder="请选择"
                                    clearable style="    width: 200px;" size="default">
                                <Option v-for="item in operateStatusList" :value="item.value" :key="item.value">{{
                                    item.title }}
                                </Option>
                            </Select>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <FormItem label="申请时间" id="applyTime">
                            <Date-picker type="date" disabled v-model="companyForm.applyTime" size="default"
                                         style="width: 200px"></Date-picker>
                        </FormItem>
                    </i-col>
                </Row>
                <Row>
                    <i-col span="8">
                        <Form-item label="月单申请数" prop="monthlyApplicationNum">
                            <Input type="text" size="default" v-bind:disabled="disabled" v-model="companyForm.monthlyApplicationNum" clearable
                                   placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="总单申请数" prop="totalApplicationNum">
                            <Input type="text" size="default" v-bind:disabled="disabled" v-model="companyForm.totalApplicationNum" clearable
                                   placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                    <Button @click="openFileUpload" size="large"
                            style=" color: #2b85e4;   background-color:white;border: none;float: right"
                            id="setUploadOrSee">附件上传
                    </Button>
                </Row>
            </Form>
        </div>
        <div v-if="isShowFile">
            <!--附件-->
            <file-operation  :uploadParam="uploadParam" :isInt="canUpload" :path="path" :read-only="readonly"></file-operation>
        </div>
        <Modal :title="modalTitle" v-model="blackApplyVisible" :mask-closable='false' :width="500"
               :styles="{top: '100px'}">
            <Form ref="blackApplyForm" :label-width="70">
                <FormItem label="申请原因" prop="blacklistReason">
                    <Input v-model="blacklistReason" class="w400" placeholder="请输入黑名单申请原因" type="textarea" :rows="6"/>
                </FormItem>
            </Form>
            <div slot="footer" style="text-align:center;">
                <Button type="text" @click="cancel">取消</Button>
                <Button type="primary" @click="join">提交</Button>
            </div>
        </Modal>
    </div>
    </card>
</template>
<script>
    import {getLocation, getAreaValueById, getBaseInfo} from "@/projects/afs-channel/api/common/common";
    import {
        getNewMainAreaById
    } from "@/projects/afs-channel/api/dealer/dealer";
    import {
        addAffiliationInfo,
        upDateAffiliationInfo,
        upDateStopAffiliationInfo,
        saveBlack,
        checkBlack,
        getAffiliationInfoById
    } from "@/projects/afs-channel/api/affiliation/affiliationAddEdit";
    import {getDictDataByType} from "@/projects/basic/api/admin/datadic";
    import {saveThirdOrNetCar} from "@/projects/afs-channel/api/affiliation/examineThirdOrNetCar";
    import { getBaseInfoByRole } from "@/projects/afs-channel/api/common/common";
    import FileOperation from "_p/basic/pages/image/upload-file/fileOperation.vue";
    import FilePreview from "_p/basic/pages/image/upload-file/contractFile/preview";
    import {checkFile} from "_p/basic/api/image/image-upload";
    import * as applyUtils from '_p/afs-apply/assets/js/utils.js'

    export default {
        components: {
            FileOperation,
            FilePreview,
        },
        data() {
            const validateMobile = (rule, value, callback) => {
                let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
                if (!reg.test(value)) {
                    callback(new Error("手机号格式错误"));
                } else {
                    callback();
                }
            };
            const validateCapital = (rule, value, callback) => {
                let reg = 500000;
                if (reg > value) {
                    callback(new Error("注册资本不能少于50万"));
                } else {
                    callback();
                }
            };
            const validateFoundedTime = (rule, value, callback) => {
                let timeRole = new Date() - value;
                $('#operation_year').val(timeRole);
            };
            const validateOperationYears = (rule, value, callback) => {
                let reg = 1;
                if (reg > value) {
                    callback(new Error("已运营年限不能少于1年"));
                } else {
                    callback();
                }
            };
            const validIdCardNum = (rule, value, callback) => {
                //长度校验
                if (value != "") {
                    if (value.length != 18) {
                        return callback(new Error('输入有误，身份证号长度需为18位!'));
                    }
                    //格式和日期校验
                    let pattern = /^\d{6}(1[8-9]|[2-9][0-9])\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{3}(\d|X)$/;
                    if (!pattern.test(value)) {
                        return callback(new Error('输入有误，请检查身份证号格式!'));
                    }
                    //省份地址编码校验
                    var city = {
                        11: "北京",
                        12: "天津",
                        13: "河北",
                        14: "山西",
                        15: "内蒙古",
                        21: "辽宁",
                        22: "吉林",
                        23: "黑龙江 ",
                        31: "上海",
                        32: "江苏",
                        33: "浙江",
                        34: "安徽",
                        35: "福建",
                        36: "江西",
                        37: "山东",
                        41: "河南",
                        42: "湖北 ",
                        43: "湖南",
                        44: "广东",
                        45: "广西",
                        46: "海南",
                        50: "重庆",
                        51: "四川",
                        52: "贵州",
                        53: "云南",
                        54: "西藏 ",
                        61: "陕西",
                        62: "甘肃",
                        63: "青海",
                        64: "宁夏",
                        65: "新疆",
                        71: "台湾",
                        81: "香港",
                        82: "澳门",
                        91: "国外 "
                    };
                    if (!city[value.substr(0, 2)]) {
                        return callback(new Error('输入有误，请检查身份证号地址编码是否正确!'));
                    }
                    //最后一位校验码校验
                    if (value.length == 18) {
                        value = value.split('');
                        //∑(ai×Wi)(mod 11)
                        //加权因子
                        let factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
                        //校验位
                        let parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
                        let sum = 0;
                        let ai = 0;
                        let wi = 0;
                        for (let i = 0; i < 17; i++) {
                            ai = value[i];
                            wi = factor[i];
                            sum += ai * wi;
                        }
                        let last = parity[sum % 11];
                        if (last != value[17]) {
                            return callback(new Error('校验失败，请输入正确的身份证号!'));
                        }
                    }
                    return callback();
                } else {
                    return callback();
                }
            };
            let isSocValiate = (rule, value, callback) => {
                if (value) {
                    if (!applyUtils.isMoreCharNum(value)) {
                        callback(new Error("格式为英文与数字或纯数字"))
                        return;
                    } else {
                        if (value.length != 18) {
                            callback(new Error("社会统一信用代码位数为18位"))
                            return;
                        }
                    }
                }
                callback()
            };
            return {
                //附件部分
                readonly:false,
                uploadParam: {
                    busiNo: "",
                    belongNo: "",
                    busiType: "",
                    busiData: {}
                },
                canUpload:true,
                path:"channel",
                // 下面是用于权限控制的 01:代表新车  02 代表二手车  03代表新车二手车都有
                businessType: null,
                ownBusinessType: null,

                // 下面是代表管理员的权限 01:代表新车  02 代表二手车  03代表新车二手车都有
                businessManage: null,
                ownBusinessManage: null,
                black: false, //是否显示黑名单申请对话框
                blacklistReason: null, // 申请黑名单原因
                moveComment: false,
                busiTypePage: '',
                location: [],
                saveType: 0,
                affiliatedId: '',
                domicValue: "domicLocation",
                options: {
                    disabledDate(date) {
                        return date && date.valueOf() > Date.now();
                    }
                },
                channelList: [],
                procity: [],
                operateStatusList: [],
                operationYears: '',
                isShowFile: false,
                sqqyids: '',
                disabledSingle: true,
                disabledGroup: '是',
                loading: true,
                operationLoading: false,
                importLoading: false,
                spinShow: false,
                loadingExport: true,
                disabled: null,
                drop: false,
                disabledTime: null,
                blackApplyVisible: false,
                updateStatus: '',
                dropDownContent: "展开",
                dropDownIcon: "ios-arrow-down",
                viewImage: false,
                selectDate: null,
                modelType: 0,
                showType: 0,
                affid: "",
                modalTitle: "",
                is: {
                    disabled: null,
                },
                companyForm: {
                    disabled: null,
                    busiType: "",
                    channelId: "",
                    whetherLicence: '',
                    affiliatedName: '',
                    socUniCrtCode: "",
                    foundedTime: "",
                    transPermitValidity: "",
                    legalPersonName: "",
                    legalPersonTel: "",
                    legalPersonIdcard: "",
                    oprTermValidity: "",
                    operationYears: "",
                    registeredProvince: "",
                    registeredCity: "",
                    registeredAddress: "",
                    termValidity: "",
                    operateVehicles: "",
                    operateStatus: "",
                    longTermOrNot: false,
                    type: null,
                    // 省市用的
                    position: "",
                    monthlyApplicationNum: "",
                    totalApplicationNum: "",
                    domicLocation: [],
                    isOrNotApply: 0,
                },
                companyFormValidate: {
                    foundedTime: [
                        {required: true, message: "成立时间不能空", type: "date", trigger: "blur"},
                    ],
                    channelId: [
                        {required: true, message: "合作商名称不能空", trigger: "change"}
                    ],
                    affiliatedName: [
                        {required: true, message: "挂靠公司名称不能空", trigger: "blur"}
                    ],
                    socUniCrtCode: [
                        {required: true, message: "社会统一信用代码不能空", trigger: "blur"},
                        {validator:isSocValiate,trigger: 'blur'}
                    ],
                    legalPersonName: [
                        {required: true, message: "法人姓名不能空", trigger: "blur"}
                    ],
                    legalPersonTel: [
                        {required: true, message: "法人联系方式不能空", trigger: "blur"},
                        {validator: validateMobile, trigger: "blur"}
                    ],
                    legalPersonIdcard: [
                        {
                            type: "string", max: 18, min: 18,
                            pattern: /^\d{6}(1[8-9]|[2-9][0-9])\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/,
                            message: "请输入正确的身份证号",
                            trigger: "blur"
                        },
                        {validator: validIdCardNum, trigger: 'blur'}
                    ],
                    operationYears: [
                        {required: true, message: "已运营年限不能空", trigger: "blur"},
                        {validator: validateOperationYears, trigger: "change"}
                    ],
                    registeredCapital: [
                        {required: true, message: "注册资本不能空", trigger: "blur"},
                        {
                            type: 'number', message: '应输入数字',
                            transform(value) {
                                return Number(value);
                            }
                        },
                        {validator: validateCapital, trigger: "blur"}
                    ],
                    registeredAddress: [
                        {required: true, message: "注册地址不能空", trigger: "blur"}
                    ],
                    operateStatus: [
                        {required: true, message: "经营状态不能空", trigger: "change"}
                    ],
                    domicLocation: [
                        {required: true, message: "注册省市不能为空", trigger: "change", type: "array"}
                    ],
                    monthlyApplicationNum: [
                        {required: true, message: "请填写月申请单数", trigger: "blur"},
                    ],
                    totalApplicationNum: [
                        {required: true, message: "请填写总申请单数", trigger: "blur"},
                    ]
                },
                requeirOprTermValidity: [
                    {required: true, type: "date", message: "营业期限不能空", trigger: "change"}
                ],
                submitLoading: false
            };
        },
        methods: {
            socValite(){
                this.companyForm.socUniCrtCode=this.companyForm.socUniCrtCode.toUpperCase();
            },
            init() {
                if (this.afs.getPageParams(this).type == 1) {
                    this.getTime();
                    this.modelType = 0;
                    this.saveType = 4;
                    this.getRole();
                } else {
                    this.companyForm.id = this.afs.getPageParams(this).id;
                    this.affiliatedId = this.companyForm.id;
                    if (this.afs.getPageParams(this).type == 2) {
                        this.updateStatus = this.afs.getPageParams(this).updateStatus;
                        if (this.updateStatus == "05" || this.updateStatus == "00") {
                            this.is.disabled = "disabled";
                            this.saveType = 3;
                        } else {
                            this.saveType = 4;
                        }
                        this.modelType = 1;
                    } else if (this.afs.getPageParams(this).type == 3) {
                        this.updateStatus = this.afs.getPageParams(this).updateStatus;
                        this.modelType = 2;
                        if (this.updateStatus == "00") {
                            this.showType = 1;
                        }
                        this.readonly=true;
                    }
                    this.getById();
                }
                ;
            },
            // 查询自己的权限
            getRole() {
                console.log("我要过来判断权限");
                console.log(this.$store.state.user.roles.toString());
                // 判断是管理员  全都可以操作
                if (this.$store.state.user.roles.toString().indexOf("ROLE_ADMIN") != -1) {
                    this.businessType = "03";
                    this.ownBusinessType = "03";
                    console.log("我是管理员");
                } else {
                    // 说明不是管理员 那么需要判断他有哪些管理角色
                    if (
                        this.$store.state.user.roles
                            .toString()
                            .indexOf("ROLE_OTHER_MANAGE_THIRD_AFFILIATED") != -1 ||this.$store.state.user.roles
                            .toString()
                            .indexOf("ROLE_OTHER_SEE_THIRD_AFFILIATED") != -1
                    ) {
                        // 说明是非直营管理
                        this.businessType = "03";
                        console.log("我是非直营");
                    }

                    // 再去判断直营的角色属性
                    if (
                        this.$store.state.user.roles
                            .toString()
                            .indexOf("ROLE_OWN_MANAGE_THIRD_AFFILIATED") != -1 ||this.$store.state.user.roles
                            .toString()
                            .indexOf("ROLE_OWN_SEE_THIRD_AFFILIATED") != -1
                    ) {
                        //我是直营的属性
                        this.ownBusinessType = "03";
                        console.log("我是直营");
                    }
                }
                this.getBaseInfoByRole();
            },
            // 获取合作商信息接口
            getBaseInfoByRole() {
                let param = {
                    status: null,
                    channelId: null,
                    businessType:this.businessType,
                    ownBusinessType:this.ownBusinessType
                };
                getBaseInfoByRole(param).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        this.channelList = res.data;
                    }
                });
            },
            closeThisTag() {
                this.afs.closeTab(this);
                this.$router.push({path: '/affiliationApplyThird'});
            },
            // 根据id 去查询数据
            getById() {
                let param = {id: this.companyForm.id};
                getAffiliationInfoById(param).then(res => {
                    this.operationLoading = false;
                    if (res.code === "0000") {
                        if (this.modelType === 2) {
                            let setUploadOrSee = document.getElementById("setUploadOrSee");
                            setUploadOrSee.innerText = "附件查看";
                            this.readonly=true;
                            this.disabled = "disabled";
                            this.is.disabled = "disabled";
                            this.disabledTime = "disabled";
                            this.companyForm.disabled = "disabled";
                        }
                        this.companyForm = res.data;
                        if (this.companyForm.longTermOrNot == "1") {
                            this.companyForm.longTermOrNot = true;
                            this.companyForm.disabled = "disabled";
                            this.companyForm.oprTermValidity = `${9999}/${12}/${31}`;
                        } else {
                            this.companyForm.longTermOrNot = false;
                        }
                        if (this.companyForm.whetherLicence == "0") {
                            this.disabledTime = "disabled";
                        }
                        this.companyForm.operationYears = this.companyForm.operationYears.toString();
                        this.companyForm.registeredCapital = this.companyForm.registeredCapital.toString();
                        if (typeof this.companyForm.monthlyApplicationNum != "undefined") {
                            this.companyForm.monthlyApplicationNum = this.companyForm.monthlyApplicationNum.toString();
                        }
                        if (typeof this.companyForm.totalApplicationNum != "undefined") {
                            this.companyForm.totalApplicationNum = this.companyForm.totalApplicationNum.toString();
                        }
                        // 地址信息
                        this.companyForm.domicLocation = [
                            this.companyForm.registeredProvince,
                            this.companyForm.registeredCity
                        ];
                    }
                });
            },
            Commit(name) {
                this.companyForm.operationYears = this.companyForm.operationYears.toString();
                if(this.companyForm.foundedTime!=""){
                    this.companyForm.foundedTime=new Date(this.companyForm.foundedTime);
                }
                if(this.companyForm.transPermitValidity!=""){
                    this.companyForm.transPermitValidity=new Date(this.companyForm.transPermitValidity);
                }
                if(this.companyForm.oprTermValidity!=""){
                    this.companyForm.oprTermValidity=new Date(this.companyForm.oprTermValidity);
                }
                if(this.companyForm.termValidity!=""){
                    this.companyForm.termValidity=new Date(this.companyForm.termValidity);
                }
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        if(Number.parseFloat(this.companyForm.monthlyApplicationNum)>Number.parseFloat(this.companyForm.totalApplicationNum)){
                            this.$Message.error("月单申请数不能大于总单申请数");
                            return;
                        }
                        console.log(this.companyForm);
                        this.uploadParam.busiNo = this.companyForm.id;
                        this.uploadParam.belongNo = this.companyForm.id
                        this.uploadParam.busiData = {};
                        this.uploadParam.busiType = "affiliateApplyThird";
                        checkFile(this.uploadParam).then(res => {
                            if (res.code === '0000') {
                                if (this.modelType == 0) {
                                    if (this.procity.length != 0 && (this.procity.indexOf(this.companyForm.domicLocation[0]) == -1 || this.procity.indexOf(this.companyForm.domicLocation[1]) == -1)) {
                                        this.$Message.error(
                                            {
                                                content: "当前注册地址不在该合作商的授权区域内！",
                                                duration: 3
                                            });
                                    } else {
                                        let params = {
                                            blacklistType: '02',
                                            idType: '02',
                                            idCode: this.companyForm.socUniCrtCode,
                                        }
                                        checkBlack(params).then(res => {
                                            if (res.code === "0000") {
                                                if (res.weatherBlackList == "0") {
                                                    this.companyForm.registeredProvince = this.companyForm.domicLocation[0];
                                                    this.companyForm.registeredCity = this.companyForm.domicLocation[1];
                                                    this.companyForm.busiType = "01";
                                                    this.companyForm.saveOrCommit = "commit";
                                                    this.companyForm.operationYears = Number(this.companyForm.operationYears);
                                                    if (this.companyForm.longTermOrNot == "0" || this.companyForm.longTermOrNot == false) {
                                                        this.companyForm.longTermOrNot = "0";
                                                    } else {
                                                        this.companyForm.longTermOrNot = "1";
                                                    }
                                                    if (this.updateStatus == "05" || this.updateStatus == "00") {
                                                        upDateStopAffiliationInfo(this.companyForm).then(res => {
                                                            this.submitLoading = false;
                                                            if (res.code === "0000") {
                                                                if (!res.data) {
                                                                    this.$Message.error(res.msg);
                                                                } else {
                                                                    this.$Message.success("申请成功");
                                                                    this.userModalVisible = false;
                                                                    let param = {id: this.companyForm.id};
                                                                    saveThirdOrNetCar(param);
                                                                    this.afs.closeTab(this);
                                                                    this.$router.push({path: '/affiliationApplyThird'});
                                                                }
                                                            }
                                                        });
                                                    } else {
                                                        if (this.affiliatedId == "") {
                                                            addAffiliationInfo(this.companyForm).then(res => {
                                                                this.submitLoading = false;
                                                                if (res.code === "0000") {
                                                                    if (!res.data) {
                                                                        this.$Message.error(res.msg);
                                                                    } else {
                                                                        this.$Message.success("申请成功");
                                                                        this.userModalVisible = false;
                                                                        this.affiliatedId = res.data.id;
                                                                        this.companyForm.id = this.affiliatedId;
                                                                        let param = {id: this.companyForm.id};
                                                                        saveThirdOrNetCar(param);
                                                                        this.afs.closeTab(this);
                                                                        this.$router.push({path: '/affiliationApplyThird'});
                                                                    }
                                                                }
                                                            });
                                                        } else {
                                                            this.companyForm.id = this.affiliatedId;
                                                            upDateAffiliationInfo(this.companyForm).then(res => {
                                                                this.submitLoading = false;
                                                                if (res.code === "0000") {
                                                                    if (!res.data) {
                                                                        this.$Message.error(res.msg);
                                                                    } else {
                                                                        this.$Message.success("申请成功");
                                                                        this.userModalVisible = false;
                                                                        this.affiliatedId = res.data.id;
                                                                        this.companyForm.id = this.affiliatedId;
                                                                        let param = {id: this.companyForm.id};
                                                                        saveThirdOrNetCar(param);
                                                                        this.afs.closeTab(this);
                                                                        this.$router.push({path: '/affiliationApplyThird'});
                                                                    }
                                                                }
                                                            });
                                                        }
                                                    }
                                                } else {
                                                    this.$Message.error("该挂靠公司已被加入黑名单");
                                                }
                                            }
                                        });
                                    }
                                } else {
                                    let params = {
                                        blacklistType: '02',
                                        idType: '02',
                                        idCode: this.companyForm.socUniCrtCode,
                                    }
                                    checkBlack(params).then(res => {
                                        if (res.code === "0000") {
                                            if (res.weatherBlackList == "0") {
                                                this.companyForm.registeredProvince = this.companyForm.domicLocation[0];
                                                this.companyForm.registeredCity = this.companyForm.domicLocation[1];
                                                this.companyForm.busiType = "01";
                                                this.companyForm.saveOrCommit = "commit";
                                                this.companyForm.operationYears = Number(this.companyForm.operationYears);
                                                if (this.companyForm.longTermOrNot == "0" || this.companyForm.longTermOrNot == false) {
                                                    this.companyForm.longTermOrNot = "0";
                                                } else {
                                                    this.companyForm.longTermOrNot = "1";
                                                }
                                                if (this.updateStatus == "05" || this.updateStatus == "00") {
                                                    upDateStopAffiliationInfo(this.companyForm).then(res => {
                                                        this.submitLoading = false;
                                                        if (res.code === "0000") {
                                                            if (!res.data) {
                                                                this.$Message.error(res.msg);
                                                            } else {
                                                                this.$Message.success("申请成功");
                                                                this.userModalVisible = false;
                                                                let param = {id: this.companyForm.id};
                                                                saveThirdOrNetCar(param);
                                                                this.afs.closeTab(this);
                                                                this.$router.push({path: '/affiliationApplyThird'});
                                                            }
                                                        }
                                                    });
                                                } else {
                                                    if (this.affiliatedId == "") {
                                                        addAffiliationInfo(this.companyForm).then(res => {
                                                            this.submitLoading = false;
                                                            if (res.code === "0000") {
                                                                if (!res.data) {
                                                                    this.$Message.error(res.msg);
                                                                } else {
                                                                    this.$Message.success("申请成功");
                                                                    this.userModalVisible = false;
                                                                    this.affiliatedId = res.data.id;
                                                                    this.companyForm.id = this.affiliatedId;
                                                                    let param = {id: this.companyForm.id};
                                                                    saveThirdOrNetCar(param);
                                                                    this.afs.closeTab(this);
                                                                    this.$router.push({path: '/affiliationApplyThird'});
                                                                }
                                                            }
                                                        });
                                                    } else {
                                                        upDateAffiliationInfo(this.companyForm).then(res => {
                                                            this.submitLoading = false;
                                                            if (res.code === "0000") {
                                                                if (!res.data) {
                                                                    this.$Message.error(res.msg);
                                                                } else {
                                                                    this.$Message.success("申请成功");
                                                                    this.userModalVisible = false;
                                                                    this.affiliatedId = res.data.id;
                                                                    this.companyForm.id = this.affiliatedId;
                                                                    let param = {id: this.companyForm.id};
                                                                    saveThirdOrNetCar(param);
                                                                    this.afs.closeTab(this);
                                                                    this.$router.push({path: '/affiliationApplyThird'});
                                                                }
                                                            }
                                                        });
                                                    }
                                                }
                                            } else {
                                                this.$Message.error("该挂靠公司已被加入黑名单");
                                            }
                                        }
                                    });
                                }
                            }else{
                                this.$Message.error("请补全影像件信息！");
                            }
                        });
                    } else {
                        this.$Message.error('请补全信息');
                    }
                })
            },
            Save(name) {
                if (this.modelType == 0) {
                    if (this.companyForm.channelId == null || this.companyForm.channelId == "") {
                        this.$Message.error("请选择合作商");
                        return;
                    }
                }
                if (this.companyForm.affiliatedName == null || this.companyForm.affiliatedName == "") {
                    this.$Message.error("请输入挂靠公司名称");
                    return;
                }
                if (this.companyForm.socUniCrtCode == null || this.companyForm.socUniCrtCode == "") {
                    this.$Message.error("请输入社会统一信用代码");
                    return;
                }
                if(this.companyForm.foundedTime!=""){
                    this.companyForm.foundedTime=new Date(this.companyForm.foundedTime);
                }
                if(this.companyForm.transPermitValidity!=""){
                    this.companyForm.transPermitValidity=new Date(this.companyForm.transPermitValidity);
                }
                if(this.companyForm.oprTermValidity!=""){
                    this.companyForm.oprTermValidity=new Date(this.companyForm.oprTermValidity);
                }
                if(this.companyForm.termValidity!=""){
                    this.companyForm.termValidity=new Date(this.companyForm.termValidity);
                }
                let params = {
                    blacklistType: '02',
                    idType: '02',
                    idCode: this.companyForm.socUniCrtCode,
                }
                checkBlack(params).then(res => {
                    if (res.code === "0000") {
                        if (res.weatherBlackList == "0") {
                            this.companyForm.registeredProvince = this.companyForm.domicLocation[0];
                            this.companyForm.registeredCity = this.companyForm.domicLocation[1];
                            this.companyForm.busiType = "01";
                            this.companyForm.saveOrCommit = "save";
                            this.companyForm.operationYears = Number(this.companyForm.operationYears);
                            if (this.companyForm.longTermOrNot == "0" || this.companyForm.longTermOrNot == false) {
                                this.companyForm.longTermOrNot = "0";
                            } else {
                                this.companyForm.longTermOrNot = "1";
                            }
                            this.spinShow=true;
                            if (this.affiliatedId == "") {
                                addAffiliationInfo(this.companyForm).then(res => {
                                    this.submitLoading = false;
                                    if (res.code === "0000") {
                                        if (!res.data) {
                                            this.spinShow=false;
                                            this.$Message.error(res.msg);
                                        } else {
                                            this.spinShow=false;
                                            this.$Message.success("保存成功");
                                            this.userModalVisible = false;
                                            this.affiliatedId = res.data.id;
                                            this.companyForm.id = this.affiliatedId
                                        }
                                    }
                                }).catch(() => {
                                    this.spinShow=false;
                                    this.submitLoading = false;
                                });
                            } else {
                                upDateAffiliationInfo(this.companyForm).then(res => {
                                    this.submitLoading = false;
                                    if (res.code === "0000") {
                                        if (!res.data) {
                                            this.spinShow=false;
                                            this.$Message.error(res.msg);
                                        } else {
                                            this.spinShow=false;
                                            this.$Message.success("保存成功");
                                            this.userModalVisible = false;
                                            this.affiliatedId = res.data.id;
                                            this.companyForm.id = this.affiliatedId
                                        }
                                    }
                                }).catch(() => {
                                    this.spinShow=false;
                                    this.submitLoading = false;
                                });
                            }
                        } else {
                            this.$Message.error("该挂靠公司已被加入黑名单");
                        }
                    }
                }).catch(() => {
                });
            },

            blacklist() {
                this.modalTitle = "确认将合作商加入黑名单吗？";
                this.blackApplyVisible = true;
            },
            cancel() {
                //关闭黑名单窗口
                this.blackApplyVisible = false;
            },
            // 申请加入黑名单
            join() {
                if (this.blacklistReason == null || this.blacklistReason == '' || this.blacklistReason == undefined) {
                    this.$Message.error('请输入申请原因');
                    return;
                }
                let parms = {
                    blacklistType: '02',
                    idType: '02',
                    idCode: this.companyForm.socUniCrtCode,
                    blacklistReason: this.blacklistReason,
                    blackName: this.companyForm.affiliatedName
                }
                saveBlack(parms).then(res => {
                    if (res.code === "0000") {
                        this.$Message.success("申请成功！");
                        this.cancel();
                    }
                }).catch(() => {

                });
            },
            selectRadio(value) {
                this.whetherLicence = value;
                if (value == "0") {
                    this.disabledTime = "disabled";
                    this.companyForm.transPermitValidity = "";
                } else {
                    this.disabledTime = null;
                    this.companyForm.transPermitValidity = "";
                }
            },
            openFileUpload() {
                this.isShowFile = !this.isShowFile;
                if(this.companyForm.id){
                    this.initGetFilterParams();
                }else{
                    this.isShowFile=false;
                    this.$Message.error("请先保存数据");
                }
            },
            initGetFilterParams() {
                this.uploadParam.busiNo = this.companyForm.id;
                this.uploadParam.belongNo = this.companyForm.id
                this.uploadParam.busiData = {};
                this.uploadParam.busiType = "affiliateApplyThird";
            },
            selectChannel(v) {
                this.sqqyids = "";
                this.procity = [];
                getNewMainAreaById(v).then(resMainArea => {
                    this.loading = false;
                    if (resMainArea.code === "0000") {
                        for (var i = 0; i < resMainArea.data.length; i++) {
                            if (i != resMainArea.data.length - 1) {
                                this.sqqyids += resMainArea.data[i].code + ",";
                            } else {
                                this.sqqyids += resMainArea.data[i].code;
                            }
                        }
                        if (this.sqqyids != "" && this.sqqyids != null) {
                            getAreaValueById({id: this.sqqyids}).then(res => {
                                    if (res.code === "0000") {
                                        for (var i = 0; i < res.data.length; i++) {
                                            this.procity.push(res.data[i].value);
                                        }
                                    }
                                }
                            )
                        }
                    }
                })
            },
            getLocationData() {
                let param = ""
                param = {
                    level: '1',
                    upperCode: '1'
                };
                getLocation(param).then((res) => {
                    if (res.code == "0000") {
                        res.data.forEach(item => {
                            // 表明是否是父节点
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        })
                    }
                    this.location.push(...res.data);
                })
            },
            loadData(item, callback) {
                item.loading = true;
                getLocation({upperCode: item.value}).then(res => {
                    if (res.code === "0000") {
                        res.data.forEach(function (item) {
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        });
                        item.children = res.data;
                        item.loading = false;
                        callback();
                    }
                })
            },
            selectCheck(value) {
                if (value) {
                    this.requeirOprTermValidity[0].required = false;
                    this.companyForm.oprTermValidity = `${9999}/${12}/${31}`;
                    this.companyForm.disabled = "disabled";
                } else {
                    this.requeirOprTermValidity[0].required = true;
                    this.companyForm.disabled = null;
                    this.companyForm.oprTermValidity = "";

                }
            },
            getChannelList() {
                let params = {status: "00"};
                getBaseInfo(params).then(res => {
                    this.operationLoading = false;
                    if (res.code === "0000") {
                        this.channelList = res.data;
                    }
                });
            },
            changeOperationYears(e) {
                if (e != null && e != "") {
                    let foundDate = new Date(e.replace(/\-/g,"/")).getTime();
                    let date = new Date(new Date().setHours(0, 0, 0, 0)).getTime();
                    let time = date - foundDate;
                    let days = time / (3600 * 24 * 1000)/366;
                    let operationYear = days.toFixed(10);
                    operationYear=operationYear.substring(0,operationYear.lastIndexOf('.')+2);
                    this.companyForm.operationYears = operationYear;
                } else {
                    this.companyForm.operationYears = 0;
                }
            },
            // 获取当前时间
            getTime() {
                var date = new Date();
                var year = date.getFullYear(); //年 ,从 Date 对象以四位数字返回年份
                var month = date.getMonth() + 1; //月 ,从 Date 对象返回月份 (0 ~ 11) ,date.getMonth()比实际月份少 1 个月
                var day = date.getDate(); //日 ,从 Date 对象返回一个月中的某一天 (1 ~ 31)
                var hours = date.getHours(); //小时 ,返回 Date 对象的小时 (0 ~ 23)
                var minutes = date.getMinutes(); //分钟 ,返回 Date 对象的分钟 (0 ~ 59)
                var seconds = date.getSeconds(); //秒 ,返回 Date 对象的秒数 (0 ~ 59)
                //修改月份格式
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                //修改日期格式
                if (day >= 0 && day <= 9) {
                    day = "0" + day;
                }
                //修改小时格式
                if (hours >= 0 && hours <= 9) {
                    hours = "0" + hours;
                }
                //修改分钟格式
                if (minutes >= 0 && minutes <= 9) {
                    minutes = "0" + minutes;
                }
                //修改秒格式
                if (seconds >= 0 && seconds <= 9) {
                    seconds = "0" + seconds;
                }
                //格式(yyyy-mm-dd hh:mm:ss)
                var currentFormatDate =
                    year +
                    "-" +
                    month +
                    "-" +
                    day +
                    " " +
                    hours +
                    ":" +
                    minutes +
                    ":" +
                    seconds;
                this.companyForm.applyTime = currentFormatDate;
            },
            getOperateStatus() {
                let param = {
                    type: "affiliationOperateStatus"
                };
                getDictDataByType(param.type).then(res => {
                    if (res.code === "0000") {
                        this.operateStatusList = res.data;
                    }
                });
            },
        },
        mounted() {
            this.init();
            this.getLocationData();
            this.getOperateStatus();
        }
    }
</script>
<style scoped>
</style>
